package com.ruoyi.project.reportSystem.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.reportSystem.domain.AttendanceRecord;
import com.ruoyi.project.reportSystem.service.IAttendanceRecordService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 考勤报表Controller
 * 
 * @author wangshuo
 * @date 2020-05-17
 */
@RestController
@RequestMapping("/reportSystem/attendance")
public class AttendanceRecordController extends BaseController
{
    @Autowired
    private IAttendanceRecordService attendanceRecordService;

    /**
     * 查询考勤报表列表
     */
    @PreAuthorize("@ss.hasPermi('reportSystem:attendance:list')")
    @GetMapping("/list")
    public TableDataInfo list(AttendanceRecord attendanceRecord)
    {
        startPage();
        List<AttendanceRecord> list = attendanceRecordService.selectAttendanceRecordList(attendanceRecord);
        return getDataTable(list);
    }

    /**
     * 导出考勤报表列表
     */
    @PreAuthorize("@ss.hasPermi('reportSystem:attendance:export')")
    @Log(title = "考勤报表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AttendanceRecord attendanceRecord)
    {
        List<AttendanceRecord> list = attendanceRecordService.selectAttendanceRecordList(attendanceRecord);
        ExcelUtil<AttendanceRecord> util = new ExcelUtil<AttendanceRecord>(AttendanceRecord.class);
        return util.exportExcel(list, "attendance");
    }

    /**
     * 获取考勤报表详细信息
     */
    @PreAuthorize("@ss.hasPermi('reportSystem:attendance:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(attendanceRecordService.selectAttendanceRecordById(id));
    }

    /**
     * 新增考勤报表
     */
    @PreAuthorize("@ss.hasPermi('reportSystem:attendance:add')")
    @Log(title = "考勤报表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AttendanceRecord attendanceRecord)
    {
        return toAjax(attendanceRecordService.insertAttendanceRecord(attendanceRecord));
    }

    /**
     * 修改考勤报表
     */
    @PreAuthorize("@ss.hasPermi('reportSystem:attendance:edit')")
    @Log(title = "考勤报表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AttendanceRecord attendanceRecord)
    {
        return toAjax(attendanceRecordService.updateAttendanceRecord(attendanceRecord));
    }

    /**
     * 删除考勤报表
     */
    @PreAuthorize("@ss.hasPermi('reportSystem:attendance:remove')")
    @Log(title = "考勤报表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(attendanceRecordService.deleteAttendanceRecordByIds(ids));
    }
}
